<?php
header("Content-type: text/html; charset=utf-8"); 
$name = $_POST["name"];
$url = $_POST["url"];
$bz = $_POST["bz"];
include 'all.class.php';
mysql_connect("$db_host","$db_user","$db_password");
mysql_select_db("$db_name");
$urltemp=str_ireplace("http://", "", $url);
$url='http://'.$urltemp;
/*echo $url;
echo $name;
echo $url;
echo $bz;*/
echo '
<head>
<link href="sy.css" rel="stylesheet" type="text/css" />
</head>

<body >

<table width="960" border="1" align="center" cellspacing="2">
  <tr>
    <td>
';
if($name == NULL || $url==NULL)
	{
		echo "文件名或者地址不能为空";
		$result=0;
	}
	else 
	{	
	if (strpos($url,"baidu"))
	{
			$file=file_get_contents($url);
			$pattern='/a><a class="dbtn cancel singledbtn" href=(.*?)id="downFileButtom">/i';
			preg_match_all($pattern,$file,$result);	
			$tempurl=implode("",$result[1]);
			echo $tempurl;
			
			echo '</td>
  </tr>
</table>';
			
	}
	if (strpos($url,"xunlei"))
	{
			$file = file_get_contents($url);
			$pattern='/file_url=(.*?) file/';
			preg_match_all($pattern,$file,$result);
			$tempurl=implode("",$result[1]);
			echo '222222222：<br /> 
  <tr>
    <td>';
			echo $tempurl;
			
			echo '</td>
  </tr>
</table>';

	}
	$sql ="insert into url2 (name,address,bz) values ('$name','$url','$bz')";//执行的语句
	mysql_query("set names utf8");
	 $result=mysql_query($sql);
	}

echo '<table width="960" border="1" align="center" cellspacing="2">
		<tr>
			<td>
				<a href="index.php">返回首页
			</td>
			<td>';
				if ($result)
	{	
		echo '<br />';
		echo "发布成功";
		echo '<br />';
	
	} 
else 
	{
		echo '<br />';
		echo "发布失败,请联系管理员";
	}
echo '
			</td>
			<td>
				<a href="gx.php">继续提交
			</td>
		';

	
	echo "</body>";